package com.ruoyi.net.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.net.domain.ElementOspfv3PortNeighb;
import com.ruoyi.net.mapper.ElementOspfv3PortNeighbMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.net.mapper.ElementOspfv3PortMapper;
import com.ruoyi.net.domain.ElementOspfv3Port;
import com.ruoyi.net.service.IElementOspfv3PortService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * 网元-OSPFV3接口配置Service业务层处理
 * 
 * @author net
 * @date 2024-11-17
 */
@Service
public class ElementOspfv3PortServiceImpl implements IElementOspfv3PortService 
{
    @Autowired
    private ElementOspfv3PortMapper elementOspfv3PortMapper;

    @Autowired
    private ElementOspfv3PortNeighbMapper elementOspfv3PortNeighbMapper;

    /**
     * 查询网元-OSPFV3接口配置
     * 
     * @param id 网元-OSPFV3接口配置主键
     * @return 网元-OSPFV3接口配置
     */
    @Override
    public ElementOspfv3Port selectElementOspfv3PortById(String id)
    {
        return elementOspfv3PortMapper.selectElementOspfv3PortById(id);
    }

    /**
     * 查询网元-OSPFV3接口配置列表
     * 
     * @param elementOspfv3Port 网元-OSPFV3接口配置
     * @return 网元-OSPFV3接口配置
     */
    @Override
    public List<ElementOspfv3Port> selectElementOspfv3PortList(ElementOspfv3Port elementOspfv3Port)
    {
        return elementOspfv3PortMapper.selectElementOspfv3PortList(elementOspfv3Port);
    }

    /**
     * 新增网元-OSPFV3接口配置
     * 
     * @param elementOspfv3Port 网元-OSPFV3接口配置
     * @return 结果
     */
    @Override
    @Transactional
    public int insertElementOspfv3Port(ElementOspfv3Port elementOspfv3Port)
    {
        String uuid = IdUtils.simpleUUID();
        if (StringUtils.isEmpty(elementOspfv3Port.getId())) {
            elementOspfv3Port.setId(uuid);
        }
        elementOspfv3Port.setCreateBy(SecurityUtils.getUsername());
        elementOspfv3Port.setCreateTime(DateUtils.getNowDate());
        elementOspfv3Port.setUpdateBy(SecurityUtils.getUsername());
        elementOspfv3Port.setUpdateTime(DateUtils.getNowDate());
        // 批量插入
        batchInsertElementOspfv3PortNeighb(elementOspfv3Port);

        return elementOspfv3PortMapper.insertElementOspfv3Port(elementOspfv3Port);
    }

    /**
     * 修改网元-OSPFV3接口配置
     * 
     * @param elementOspfv3Port 网元-OSPFV3接口配置
     * @return 结果
     */
    @Override
    public int updateElementOspfv3Port(ElementOspfv3Port elementOspfv3Port)
    {
        elementOspfv3Port.setUpdateBy(SecurityUtils.getUsername());
        elementOspfv3Port.setUpdateTime(DateUtils.getNowDate());
        // 批量删除、更新
        elementOspfv3PortNeighbMapper.deleteElementOspfv3PortNeighbByOspfv3PortId(elementOspfv3Port.getId());
        batchInsertElementOspfv3PortNeighb(elementOspfv3Port);

        return elementOspfv3PortMapper.updateElementOspfv3Port(elementOspfv3Port);
    }

    /**
     * 批量删除网元-OSPFV3接口配置
     * 
     * @param ids 需要删除的网元-OSPFV3接口配置主键
     * @return 结果
     */
    @Override
    public int deleteElementOspfv3PortByIds(String[] ids)
    {
        return elementOspfv3PortMapper.deleteElementOspfv3PortByIds(ids);
    }

    /**
     * 删除网元-OSPFV3接口配置信息
     * 
     * @param id 网元-OSPFV3接口配置主键
     * @return 结果
     */
    @Override
    public int deleteElementOspfv3PortById(String id)
    {
        elementOspfv3PortNeighbMapper.deleteElementOspfv3PortNeighbByOspfv3PortId(id);
        return elementOspfv3PortMapper.deleteElementOspfv3PortById(id);
    }

    public void batchInsertElementOspfv3PortNeighb(ElementOspfv3Port elementOspfv3Port) {

        if (!CollectionUtils.isEmpty(elementOspfv3Port.getOspfv3NeighborList())) {
            for (ElementOspfv3PortNeighb neighb : elementOspfv3Port.getOspfv3NeighborList()) {
                neighb.setOspfv3PortId(elementOspfv3Port.getId());
                neighb.setCreateBy(SecurityUtils.getUsername());
                neighb.setCreateTime(DateUtils.getNowDate());
                neighb.setUpdateBy(SecurityUtils.getUsername());
                neighb.setUpdateTime(DateUtils.getNowDate());
            }
            elementOspfv3PortNeighbMapper.batchElementOspfv3PortNeighb(elementOspfv3Port.getOspfv3NeighborList());
        }
    }
}
